package com.zelix;

import java.io.IOException;
import java.io.Reader;

public class a5 {

    int a;
    int b;
    int c;
    public int d;
    protected int e[];
    protected int f[];
    protected int g;
    protected int h;
    protected boolean i;
    protected boolean j;
    protected Reader k;
    protected char l[];
    protected int m;
    protected int n;

    public a5(Reader reader, int i1, int j1) {
        this(reader, i1, j1, 4096);
    }

    public a5(Reader reader, int i1, int j1, int k1) {
        d = -1;
        g = 0;
        h = 1;
        i = false;
        j = false;
        m = 0;
        n = 0;
        k = reader;
        h = i1;
        g = j1 - 1;
        b = a = k1;
        l = new char[k1];
        e = new int[k1];
        f = new int[k1];
    }

    public char a()
            throws IOException {
        c = -1;
        char c1 = h();
        c = d;
        return c1;
    }

    protected void a(boolean flag) {
        char ac[] = new char[a + 2048];
        int ai[] = new int[a + 2048];
        int ai1[] = new int[a + 2048];
        try {
            if (flag) {
                System.arraycopy(l, c, ac, 0, a - c);
                System.arraycopy(l, 0, ac, a - c, d);
                l = ac;
                System.arraycopy(e, c, ai, 0, a - c);
                System.arraycopy(e, 0, ai, a - c, d);
                e = ai;
                System.arraycopy(f, c, ai1, 0, a - c);
                System.arraycopy(f, 0, ai1, a - c, d);
                f = ai1;
                m = d += a - c;
            } else {
                System.arraycopy(l, c, ac, 0, a - c);
                l = ac;
                System.arraycopy(e, c, ai, 0, a - c);
                e = ai;
                System.arraycopy(f, c, ai1, 0, a - c);
                f = ai1;
                m = d -= c;
            }
        }
        catch (Throwable throwable) {
            throw new Error(throwable.getMessage());
        }
        a += 2048;
        b = a;
        c = 0;
    }

    protected void b()
            throws IOException {
        if (m == b) {
            if (b == a) {
                if (c > 2048) {
                    d = m = 0;
                    b = c;
                } else if (c < 0) {
                    d = m = 0;
                } else {
                    a(false);
                }
            } else if (b > c) {
                b = a;
            } else if (c - b < 2048) {
                a(true);
            } else {
                b = c;
            }
        }
        int i1;
        try {
            if ((i1 = k.read(l, m, b - m)) == -1) {
                k.close();
                throw new IOException();
            } else {
                m += i1;
            }
        }
        catch (IOException ioexception) {
            d--;
            b(0);
            if (c == -1)
                c = d;
            throw ioexception;
        }
    }

    public String c() {
        if (d >= c)
            return new String(l, c, (d - c) + 1);
        else
            return new String(l, c, a - c) + new String(l, 0, d + 1);
    }

    public char[] a(int i1) {
        char ac[];
        ac = new char[i1];
        if (d + 1 >= i1) {
            System.arraycopy(l, (d - i1) + 1, ac, 0, i1);
        } else {
            System.arraycopy(l, a - (i1 - d - 1), ac, 0, i1 - d - 1);
            System.arraycopy(l, 0, ac, i1 - d - 1, d + 1);
        }
        return ac;
    }

    protected void a(char c1) {
        g++;
        if (j) {
            j = false;
            h += g = 1;
        } else if (i) {
            i = false;
            if (c1 == '\n') {
                j = true;
            } else {
                h += g = 1;
            }
        }
        switch (c1) {
            case 11: // '\013'
            case 12: // '\f'
            default:
                break;

            case 13: // '\r'
                i = true;
                break;
            case 10: // '\n'
                j = true;
                break;
            case 9: // '\t'
                g--;
                g += 8 - (g & 7);
                break;
        }
        e[d] = h;
        f[d] = g;
    }

    public void b(int i1) {
        n += i1;
        if ((d -= i1) < 0)
            d += a;
    }

    public int d() {
        return f[c];
    }

    public int e() {
        return e[c];
    }

    public int f() {
        return f[d];
    }

    public int g() {
        return e[d];
    }

    public char h()
            throws IOException {
        if (n > 0) {
            n--;
            if (++d == a)
                d = 0;
            return l[d];
        }
        if (++d >= m)
            b();
        char c1 = l[d];
        a(c1);
        return c1;
    }
}